package com.example.a022.myapplication;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.GridView;

    /**
     * Created by Administrator on 2018/6/6 0006.
     */
    public class NonScrollGridView extends GridView {

    public NonScrollGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NonScrollGridView(Context context) {
        super(context);
    }

    public NonScrollGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

//        int childViewCount = this.getChildCount();
//        for (int i=0;i<childViewCount;i++){
//            View childView = this.getChildAt(i);
//            int width = MeasureSpec.getSize(widthMeasureSpec);
//            widthMeasureSpec = MeasureSpec.makeMeasureSpec(width,
//                    MeasureSpec.AT_MOST);
//            int height =MeasureSpec.getSize(heightMeasureSpec);
//            heightMeasureSpec =MeasureSpec.makeMeasureSpec(height,
//                    MeasureSpec.AT_MOST);
//            //测量后让子View获得宽高
//            childView.measure(widthMeasureSpec, heightMeasureSpec);
//        }
    }
}
